<?php
class KolSys_Nav
{
	public static function getInstance(){
		return KolSys_Singleton::getInstance(__CLASS__);
	}

	function getPage($page,$options=false){
		global $settings;
		$x=new KolSys_Curl();
		$x->init();
		$x->setURL("{$settings['site']}/$page");
		$x->setUserAgent($settings['userAgent']);
		$x->setTimeout(30);//The maximum number of seconds to allow cURL functions to execute.
		if($options){
			if(isset($options['post'])){$paramstring=http_build_query($options['post'],'','&');$x->setPostData($paramstring);}
			if(isset($options['referer'])){$x->setReferer($options['referer']);}
			//if(isset($options['referer'])){$x->setReferer($options['referer']);}
			if(isset($options['X-Requested-With'])){
				$x->addHeader("X-Requested-With: {$options['X-Requested-With']}");
			}
			if(isset($options['addHeaders'])){
				foreach($options['addHeaders'] as $header){$x->addHeader($header);}
			}
			if(isset($options['debugMode'])){$x->setDebugMode($options['debugMode']);}
			//X-Requested-With: XMLHttpRequest
		}
		if(isset($options['setCookie'])){
			$x->setCookie($options['setCookie']);
		}else{
			$x->setCookie(KolSys_Curl_Header::getCookie());
		}
		$result=$x->dispatch();
		if(!isset($options['ignoreCookies']))
		{
			KolSys_MySQLDatabase::setDBCookie(KolSys_Curl_Header::getCookie());
		}
		
		//echo CURL_Header_Management::getLastLocation().'<hr>';flush();
		return $result;
	}
}
